package cn.sh.yhk.mapper.basic;

import cn.sh.yhk.model.basic.SMenu;
import cn.sh.yhk.model.basic.SMenuExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface SMenuMapper {
    @SelectProvider(type = SMenuSqlProvider.class, method = "countByExample")
    long countByExample(SMenuExample example);

    @DeleteProvider(type = SMenuSqlProvider.class, method = "deleteByExample")
    int deleteByExample(SMenuExample example);

    @Insert({
            "insert into s_menu (id, parent_id, ",
            "menu_name, url, menu_sort, ",
            "activity, menu_icon)",
            "values (#{id,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, ",
            "#{menuName,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{menuSort,jdbcType=INTEGER}, ",
            "#{activity,jdbcType=VARCHAR}, #{menuIcon,jdbcType=VARCHAR})"
    })
    int insert(SMenu record);

    @InsertProvider(type = SMenuSqlProvider.class, method = "insertSelective")
    int insertSelective(SMenu record);

    @SelectProvider(type = SMenuSqlProvider.class, method = "selectByExample")
    @Results(id = "SMenuMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "parent_id", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "menu_name", property = "menuName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "url", property = "url", jdbcType = JdbcType.VARCHAR),
            @Result(column = "menu_sort", property = "menuSort", jdbcType = JdbcType.INTEGER),
            @Result(column = "activity", property = "activity", jdbcType = JdbcType.VARCHAR),
            @Result(column = "menu_icon", property = "menuIcon", jdbcType = JdbcType.VARCHAR)
    })
    List<SMenu> selectByExample(SMenuExample example);

    @UpdateProvider(type = SMenuSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SMenu record, @Param("example") SMenuExample example);

    @UpdateProvider(type = SMenuSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") SMenu record, @Param("example") SMenuExample example);

    @Select("select * from s_menu where id in (select menu_id from s_role_menu where role_id=#{roleId})")
    @ResultMap(value = "SMenuMap")
    List<SMenu> selectMenuByRoleId(Long roleId);


}